﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t206Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t206_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t206Mgr mgr = new t206Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t206(e.Parameters[t206_Filter.ParamPrefix]));
            IList<t206> list = mgr.FindAllByPage_t206(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t206_Filter.ParamPrefix]);
            t206_MainStore.DataSource = list;
            t206_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t206Mgr mgr = new t206Mgr();
            RowSelectionModel sm = t206_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t206 _t206 = new t206();
                _t206.t206_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t206(_t206))
                {
                    log.Debug("t206中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t206_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t206Mgr mgr = new t206Mgr();
            t206 _t206 = new t206();
            if (Hid.Text.Length > 0)
                _t206 = mgr.FindById_t206(int.Parse(Hid.Text));
            
			_t206.t206_01 = Txtt206_01.Text.Trim();
			_t206.t206_02 = Txtt206_02.Text.Trim();
			_t206.t206_71 = Txtt206_71.Text.Trim();
			_t206.t206_72 = Txtt206_72.Text.Trim();
			_t206.t206_73 = Txtt206_73.Text.Trim();
			_t206.t206_74 = Txtt206_74.Text.Trim();
			_t206.t206_03 = Txtt206_03.Text.Trim();
			_t206.t206_75 = Txtt206_75.Text.Trim();
			_t206.t206_76 = Txtt206_76.Text.Trim();
			_t206.t206_77 = Txtt206_77.Text.Trim();
			_t206.t206_78 = Txtt206_78.Text.Trim();
			_t206.t206_04 = Txtt206_04.Text.Trim();
			_t206.t206_79 = Txtt206_79.Text.Trim();
			_t206.t206_80 = Txtt206_80.Text.Trim();
			_t206.t206_81 = Txtt206_81.Text.Trim();
			_t206.t206_82 = Txtt206_82.Text.Trim();
			_t206.t206_83 = Txtt206_83.Text.Trim();
			_t206.t206_05 = Txtt206_05.Text.Trim();
			_t206.t206_06 = Txtt206_06.Text.Trim();
			_t206.t206_07 = Txtt206_07.Text.Trim();
			_t206.t206_84 = Txtt206_84.Text.Trim();
			_t206.t206_08 = Txtt206_08.Text.Trim();
			_t206.t206_09 = Txtt206_09.Text.Trim();
			_t206.t206_10 = Txtt206_10.Text.Trim();
			_t206.t206_11 = Txtt206_11.Text.Trim();
			_t206.t206_12 = Txtt206_12.Text.Trim();
			_t206.t206_13 = Txtt206_13.Text.Trim();
			_t206.t206_70 = Txtt206_70.Text.Trim();
			_t206.t206_14 = Txtt206_14.Text.Trim();
			_t206.t206_15 = Txtt206_15.Text.Trim();
			_t206.t206_16 = Txtt206_16.Text.Trim();
			_t206.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t206(_t206);
            else
                isok = mgr.Add_t206(_t206);
            if (isok)
            {
                t206_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t206中执行了保存（插入或修改），并成功");
                t206_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}